﻿@{
    ViewBag.Title = "Manage Reference - Project Management System";
    Layout = "~/Views/Shared/_Layout.cshtml";
    
}
<h2>
    Manage Reference</h2>
<form action="" method="post" id="form" name="formProject">
<input type="hidden" id="Action" name="Action" />
<ul class="shortcut-buttons-set">
    @{if (PMS.Utilities.Utility.RoleID == 2)
      {
        <li><a class="shortcut-button" href="#" id="btnUpload"><span>
            <img src="../../Content/images/icons/page-up-icon.png" alt="icon" /><br />
            Upload</span></a></li>
        <li><a class="shortcut-button" href="#" onclick="if(DoAction('@Url.Action("Reference", "Reference")')==-1)jAlert('Please Select One Item', 'Message');">
            <span>
                <img src="../../Content/images/icons/paper_content_pencil_48.png" alt="icon" /><br />
                Edit</span></a></li>
      }
    }
    @{if (PMS.Utilities.Utility.RoleID == 3)
      {
        <li><a class="shortcut-button" href="#" onclick="if(DoAction('@Url.Action("Reference", "Reference")')==-1)jAlert('Please Select One Item', 'Message');">
            <span>
                <img src="../../Content/images/icons/Search-icon.png" alt="icon" /><br />
                View</span></a></li>
      }
    }
</ul>
<!-- End .shortcut-buttons-set -->
<div class="clear">
</div>
<!-- End .clear -->
<!-- Search -->
<input type="hidden" id="isSearch" name="isSearch" value="@ViewData["IsSearch"]" />
<div class="content-box" id="Search">
    <!-- Start Content Box -->
    <div class="content-box-header">
        <h3 id="toggleSearch">
            Search</h3>
        <div class="clear">
        </div>
    </div>
    <!-- End .content-box-header -->
    <div class="content-box-content">
        <fieldset>
            <p>
                <label class="width12 floatLeft">
                    Project Name:</label>
                <input type="text" id="txtProjectName" name="ProjectName" class="width20 input-inline text-input medium-input" value="@ViewData["ProjectName"]"/>
            </p>
            <div class="childCol">
                <p>
                    <label class="width12 floatLeft">
                        Deparment:</label>
                    @Html.DropDownList("DepartmentID", (SelectList)ViewData["DepartmentList"], new { @class = "width20 input-inline", onchange = "$('#Page').attr('value', 1);$('form').submit();" })
                </p>
            </div>
            <div class="childCol">
                <p>
                    <label class="width12 floatLeft">
                        Subject:</label>
                    @Html.DropDownList("SubjectID", (SelectList)ViewData["SubjectList"], new { @class = "width20 input-inline", onchange = "$('#Page').attr('value', 1);$('form').submit();" })
                </p>
            </div>
        </fieldset>
    </div>
</div>
<div class="content-box">
    <!-- Start Content Box -->
    <div class="content-box-header">
        <h3>
            Project List</h3>
        <div class="clear">
        </div>
    </div>
    <!-- End .content-box-header -->
    <div class="content-box-content">
        <div>
            <!-- This is the target div. id must match the href of this div's tab -->
            @{ if (TempData["Message"] != null)
               {
                <div class="notification attention png_bg">
                    <a href="#" class="close">
                        <img src="../../Content/images/icons/cross_grey_small.png" title="Close this notification"
                            alt="close" /></a>
                    <div>
                        @TempData["Message"].ToString()
                    </div>
                </div>
               }
            }
            @{ 
                var pageSize = int.Parse(ViewData[PMS.ENT.PageInfo.PageSize.ToString()].ToString());
                var pageNum = int.Parse(ViewData[PMS.ENT.PageInfo.PageNum.ToString()].ToString());
                var page = int.Parse(ViewData[PMS.ENT.PageInfo.Page.ToString()].ToString()); }
            <input type="hidden" name="groupID" id="GroupID" />
            <input type="hidden" value="@ViewData["OrderBy"]" name="orderBy" id="orderBy" />
            <input type="hidden" value="@ViewData["OrderDirection"]" name="orderDirection"
                id="orderDirection" />
            @{if (Model.Count <= 0)
              {
                <div class="RecordFound @("RecordFound" + @Model.Count)">
                    No Record Found</div>
              }
            }
            <table class="flexigird TableGrid">
                <thead>
                    <tr>
                        <th id="Selected">
                            <input class="check-all" type="checkbox" id="checkAll" />
                        </th>
                        <th id="ProjectName">
                            Project Name
                        </th>
                        <th id="Subject">
                            Subject
                        </th>
                    </tr>
                </thead>
                @*<tfoot>
                    <tr>
                        <td colspan="6">
                            @{ Html.RenderPartial("Pagination", null, ViewData); }
                            <!-- End .pagination -->
                            <div class="clear">
                            </div>
                        </td>
                    </tr>
                </tfoot>*@
                <tbody>
                    @{ for (int i = 0; i < Model.Count; i++)
                       {
                           string projectName = Model[i].ProjectName;
                           string schedule = Model[i].Schedule.ToString();
                        <tr>
                            <td>
                                <input type="checkbox" id="ProjectID" name="ProjectID" value="@Model[i].ProjectID"
                                        group="Selected" onclick="Uncheck('ProjectID');" status="@Model[i].Status" groups="@Model[i].NumberOfGroup" />
                            </td>
                            <td>
                                @Html.ActionLink(projectName, "ViewProject", new { ID = Model[i].ProjectID }, null)
                            </td>
                            <td>
                                @Model[i].SubjectName
                            </td>
                        </tr>
                       } 
                    }
                </tbody>
            </table>
            @{Html.RenderPartial("Pagination", null, ViewData); }
        </div>
        <!-- End #tab1 -->
    </div>
    <!-- End .content-box-content -->
</div>
<!-- End .content-box -->
</form>
<script language="javascript" type="text/javascript">
    $("#Referecent").addClass("current");
    $("#Reference").addClass("current");
    $("#toggleSearch").click(function () {
        if ($("#isSearch").val() == 1) {
            $("#isSearch").val(0);
        }
        else {
            $("#isSearch").val(1);
        }
    });

    $('#txtProjectName').keydown(function (event) {
        if (event.keyCode == 13) {
            $('form').submit();
        }
    });

    var isSearch = @ViewData["IsSearch"];
    if (isSearch == '1') {
        $("#Search").removeClass('closed-box');
    }
    else {
        $("#Search").addClass('closed-box');
    }

    var projectID = 0;
    var isHide = 0;
    $("#btnUpload").click(function () {
        var html = ' <h3>\
                        Reference</h3>\
                         <p>\
                            <label class="width12 floatLeft">\
                                Project:</label>\
                            <select class="width20 input-inline" id="cmbProject" >\
                                <option></option>\
                            </select>\
                        </p>\
                         <p>\
                            <label class="width12 floatLeft">\
                                Hide:</label>\
                            <input type="checkbox" name="isHide" id="isHide" />\
                            </select>\
                        </p>\
                        <div id="fileuploader"></div>\
                        </fieldset>';
        jQuery.facebox(html);


        $.post('@Url.Action("GetProjectForCMB", "Project")', function (data) {
            if (data != null) {
                //Invoice To
                var options = $("#cmbProject").attr('options');
                $("#cmbProject").children().remove();
                $.each(data.ListProject, function (index, Project) {
                    var option = new Option(Project.ProjectName, Project.ProjectID);
                    options[options.length] = option;
                });
            }
        });


        var button = $('#fileuploader')[0];
        var uploader = new qq.FileUploader({
            element: button,
            action: '@Url.Action("UploadFile", "Reference")',
            multiple: true,
            params: { projectID: projectID, isHide: isHide },
            onComplete: function () {
                jConfirm('Upload complete, reload data?', 'Message', function (r) {
                    if (r) {
                        $('form').submit();
                    }
                });
            }
        });

        $("#cmbProject").live('change', function () {
            projectID = $("#cmbProject").val();
            uploader.setParams({
                projectID: projectID,
                isHide: isHide
            });
        });


        $("#isHide").click(function () {
            if ($(this).is(':checked')) {
                isHide = 1;
            } else {
                isHide = 0;
            }
            uploader.setParams({
                projectID: projectID,
                isHide: isHide
            });
        });

    });
  
</script>
